package cn.da.shuai.cool.job.executor;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class SampleJobHandler {

    private static final Logger logger = LoggerFactory.getLogger(SampleJobHandler.class);

    @XxlJob("sampleJobHandler")
    public void sampleJobHandler() {
        String now = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        logger.info("XXL-JOB Sample Job executed at: {}", now);
        XxlJobHelper.log("XXL-JOB Sample Job executed at: {}", now);
    }

    @XxlJob("paramJobHandler")
    public void paramJobHandler() {
        String param = XxlJobHelper.getJobParam();
        logger.info("XXL-JOB Param Job executed with param: {}", param);
        XxlJobHelper.log("XXL-JOB Param Job executed with param: {}", param);
    }
}